package com.sunlands.qdcy.tongzhuo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.sunlands.qdcy.tongzhuo.model.UserDiaryReplyDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import javax.persistence.Id;
import java.util.Date;
import java.util.Objects;

/**
 * @date 2019/5/2914:21
 */
@Data
@JsonSerialize
@ApiModel(value = "日记列表之评论回复信息")
@Builder
public class UserDiaryListVO {

        @Id
        @ApiModelProperty(value = "回复id")
        private Long id;

        @ApiModelProperty(value = "日记id")
        private Long diaryId;

        @ApiModelProperty(value = "回复用户id")
        private Long replyUserId;

        @ApiModelProperty(value = "回复用户昵称")
        private String replyUserName;

        @ApiModelProperty(value = "回复用户头像")
        private String replyUserAvatarUrl;

        @ApiModelProperty(value = "回复内容")
        private String replyContent;

        @ApiModelProperty(value = "被回复的id")
        private Long replyedId;

        @ApiModelProperty(value = "被回复用户id")
        private Long replyedUserId;

        @ApiModelProperty(value = "被回复用户昵称")
        private String replyedUserName;

        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        private Date createTime;

        @ApiModelProperty(value = "回复用户目标名称")
        private String userCurrentLearnTargetName;

        @ApiModelProperty(value = "是否是作者")
        private Boolean author;

        @ApiModelProperty(value = "1:日记的回复，2:评论的回复，3:回复的回复")
        private Integer type;

        @ApiModelProperty(value = "是否赞过")
        private Boolean zan;

        @ApiModelProperty(value = "点赞数")
        private Integer zanCount;

        @ApiModelProperty(value = "回复用户id,前端冗余字段")
        private Long userId;

        @ApiModelProperty(value = "回复用户昵称,前端冗余字段")
        private String userName;

        @ApiModelProperty(value = "回复用户头像,前端冗余字段")
        private String userAvatarUrl;
        @ApiModelProperty(value = "回复用户身份信息，前端冗余字段")
        private String identityName;
        @ApiModelProperty("回复内容，前端冗余字段")
        private String commentContent;
        @ApiModelProperty(value = "点赞数，前端冗余字段")
        private Integer zanCommentCount;

        public static UserDiaryListVO from(UserDiaryReplyDO userDiaryReply) {
            return Objects.isNull(userDiaryReply) ? null : UserDiaryListVO.builder()
                    .id(userDiaryReply.getId())
                    .diaryId(userDiaryReply.getDiaryId())
                    .replyContent(userDiaryReply.getReplyContent())
                    .replyUserId(userDiaryReply.getReplyUserId())
                    .createTime(userDiaryReply.getCreateTime())
                    .replyedId(userDiaryReply.getReplyedId())
                    .replyedUserId(userDiaryReply.getReplyedUserId())
                    .type(userDiaryReply.getType())
                    .userId(userDiaryReply.getReplyUserId())
                    .commentContent(userDiaryReply.getReplyContent())
                    .build();
        }

}
